﻿Imports System.Web
Imports System.Configuration
Imports Mysoft.Map.Data


Partial Public Class openReport
    Inherits Mysoft.Map.Application.Security.AppPage

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            '初始化调用ws的相关信息
            initWsApplication()
            initWsSession()

            Dim strRptName As String = Request.QueryString("rptname")

            '屏幕报表通过报表名称来取通过报表
            Dim strRptID As String = Mysoft.Report.Page.General.GetReportGUIDByName(strRptName)

            Dim strQuery As String = String.Empty
            Dim arrQueryString As System.Collections.Specialized.NameValueCollection = Request.QueryString()

            For Each strQueryStringName As String In arrQueryString
                If strQueryStringName.ToLower() <> "rptname" Then
                    strQuery = strQuery & "&" & strQueryStringName & "=" & HttpUtility.UrlEncode(arrQueryString(strQueryStringName), System.Text.Encoding.GetEncoding("GB2312"))
                End If
            Next

            Session("Scope") = Mysoft.Report.Page.General.GetReportScopeByGUID(strRptID)

            Response.Redirect("/Report/ReportView.aspx?" & "rptid=" & strRptID & strQuery)
        End If
    End Sub

    '初始化ws所需要使用到的session信息
    Private Function initWsSession() As String
        Dim sql As String
        sql = "SELECT UserCode FROM myUser WHERE UserGUID='" + HttpContext.Current.Session("UserGUID") + "'"
        Session("UserCode") = MyDB.GetDataItemString(sql)

        sql = "SELECT Password FROM myUser WHERE UserGUID='" + HttpContext.Current.Session("UserGUID") + "'"
        Session("UserPass") = MyDB.GetDataItemString(sql)

    End Function

    '初始化ws所需要使用的application信息
    Private Function initWsApplication() As String
        If HttpContext.Current.Application("MyRptServices") Is Nothing Then
            If Not ConfigurationSettings.AppSettings("MyRptServices") Is Nothing Then
                HttpContext.Current.Application("MyRptServices") = ConfigurationSettings.AppSettings("MyRptServices")
            Else
                HttpContext.Current.Application("MyRptServices") = ""
            End If
        End If

        If HttpContext.Current.Application("MyRptAppKey") Is Nothing Then
            If Not ConfigurationSettings.AppSettings("MyRptAppKey") Is Nothing Then
                HttpContext.Current.Application("MyRptAppKey") = ConfigurationSettings.AppSettings("MyRptAppKey")
            Else
                HttpContext.Current.Application("MyRptAppKey") = ""
            End If
        End If
    End Function
End Class